package com.novax.ex.activity.provider.service;

import com.novax.ex.activity.infrastructure.entity.MallProduct;
import com.novax.ex.activity.infrastructure.entity.MallProductTitleLanguage;
import com.novax.ex.activity.infrastructure.mapper.MallProductMapper;
import com.novax.ex.activity.infrastructure.mapper.MallProductTitleLanguageMapper;
import com.novax.ex.common.base.BaseMapper;
import com.novax.ex.common.base.BaseService;
import com.novax.ex.common.enums.LanguageType;
import com.novax.ex.common.exception.BusinessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import jakarta.annotation.Resource;
import java.util.Date;

/**
 * Description:商品配置
 *
 * @author Deucalion@novax.email
 * @date 2023/2/21 17:21
 */
@Service
public class MallProductService extends BaseService {
    @Resource
    private MallProductMapper mallProductMapper;
    @Resource
    private MallProductTitleLanguageMapper mallProductTitleLanguageMapper;
    @Override
    protected BaseMapper getBaseMapper() {
        return mallProductMapper;
    }

    @Transactional
    public boolean addProduct(MallProduct entity){
        int result1 = mallProductMapper.insertSelective(entity);
        if(1 != result1){
            throw new BusinessException("存储商品信息失败");
        }
        MallProductTitleLanguage titleLanguage = new MallProductTitleLanguage();
        titleLanguage.setMallProductId(entity.getId());
        titleLanguage.setLanguage(LanguageType.zh_tc.getType());
        titleLanguage.setContent(entity.getTitle());
        int result2 = mallProductTitleLanguageMapper.insertSelective(titleLanguage);
        if(1 != result2){
            throw new BusinessException("存储商品信息失败");
        }
        return true;
    }

    /** 数据软删除 */
    public boolean removeById(Long id, Long adminId) {
        return mallProductMapper.removeById(id,adminId) > 0;
    }
}
